import java.sql.*;

import oracle.jdbc.OracleTypes;
public class Test03 {
	public static void main(String[] args){
		try{
			Connection conn = JDBCUtil.getConnection();
			//Save a record
			String sp1 = "{? = call saveUser(?,?)}";
			CallableStatement cs = conn.prepareCall(sp1);
			cs.registerOutParameter(1, Types.INTEGER);
			cs.setString(2, "Mandy");
			cs.setInt(3,52);
			cs.execute();
			System.out.println("Returned value: "+cs.getInt(1));
			//Retreve all records
			String sp2 = "{? = call queryUser()}";
			cs = conn.prepareCall(sp2);
			cs.registerOutParameter(1, OracleTypes.CURSOR);  //return CURSOR type
			cs.execute();
			ResultSet rs = (ResultSet)cs.getObject(1);  //downcast to ResultSet
			while (rs.next()){  //Pointer
				System.out.println(rs.getString("Name")+"\t"+rs.getInt("Age"));
			}
			rs.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
